package main

import (
	"git.oschina.net/xiaoqiaotq/hello-go/cmdb"
	"bytes"
	"encoding/json"
	"io"
	"fmt"
)

func main() {
	cmdb.GetServer("172.16.2.19","aa","","")
	//cmdb.GetServer("","")
	//field:=[]string{}
	//body := &cmdb.QueryRequest{ "primaryIp::eq::172.16.2.19",[]string{}}
	//toJson(body,true)


	//buf := &bytes.Buffer{}
	//err := json.NewEncoder(buf).Encode(p.payload)
	//if err != nil {
	//	return nil, err
	//}
	//return buf, nil


	// GET request
	//resp, err := resty.R().Get("http://httpbin.org/get")
	//
	//// explore response object
	//fmt.Printf("\nError: %v", err)
	//fmt.Printf("\nResponse Status Code: %v", resp.StatusCode())
	//fmt.Printf("\nResponse Status: %v", resp.Status())
	//fmt.Printf("\nResponse Time: %v", resp.Time())
	//fmt.Printf("\nResponse Recevied At: %v", resp.ReceivedAt())
	//fmt.Printf("\nResponse Body: %v", resp)     // or resp.String() or string(resp.Body())
}

func toJson(any interface{},indent bool)  (io.Reader, error){
	buf := &bytes.Buffer{}
	encoder := json.NewEncoder(buf)
	if indent{
		encoder.SetIndent("", "\t")
	}
	err :=encoder.Encode(any)
	if err != nil {
		return nil, err
	}
	fmt.Println(buf)
	return buf, nil
}
